package com.xiaojie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaojie.entity.Video;
import com.xiaojie.service.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 视频 前端控制器
 * </p>
 *
 * @author xiaojie
 * @since 2022-07-28
 */
@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    private IVideoService videoService;
    @GetMapping("/videos")
    public Map findAll(@RequestParam("page") Integer curPage,
                       @RequestParam(value = "per_page",defaultValue = "5") Integer pageSize,
                       @RequestParam(value = "id",required = false) Integer vid,
                       @RequestParam(value = "name",required = false) String name,
                       @RequestParam(value = "category_id",required = false) Integer categoryId,
                       @RequestParam(value = "uploader_name",required = false) String username){
        Page<Video> page = new Page<>(curPage,pageSize);
        Page<Video> allByKeywords = videoService.findAllByKeywords(page, vid, name, categoryId, username);
        Map<String, Object> map = new HashMap<>();
        //总条数
        map.put("total_count",page.getTotal());
        //当前页信息
        map.put("items",page.getRecords());
        return map;
    }
}

